﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Leaveword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblMessage.Text = "";
        string sql = "select * from Leaveword_Info where leaIsShow=1 order by leaTime desc ";
        gvLeave.DataSource = DataAccess.GetDataTable(sql, null);
        gvLeave.DataBind();

    }
    protected void btOK_Click(object sender, EventArgs e)
    {
        string sql = "insert into Leaveword_Info(leaName,leaIP,leaTitle,leaContent,leaTime)values('" + txtName.Text + "','" + Request.UserHostAddress.ToString() + "','" + txtTitle.Text + "','" + txtContent.Text + "','" + DateTime.Now + "')";
        if (DataAccess.ExecuteSQL(sql, null))
        {
            lblMessage.Text = "留言成功,请等待管理员认证";
            txtName.Text = null;
            txtTitle.Text = null;
            txtContent.Text = null;
        }
        else
        {
            lblMessage.Text = "留言失败，请重试";
        }
    }
    protected void btReset_Click(object sender, EventArgs e)
    {
        txtName.Text = null;
        txtTitle.Text = null;
        txtContent.Text = null;
    }

    protected void gvLeave_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvLeave.PageIndex = e.NewPageIndex;
        gvLeave.DataBind();
    }
}